package com.crm.dao;

import java.util.List;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.crm.entity.UserRoles;
import com.crm.util.ApplicationContext;

public class UserRolesDAO {
	protected final Log logger = LogFactory.getLog(getClass());

	public  int insert(UserRoles ur) throws Exception{
		Session session =  ApplicationContext.getHiberSession().openSession();
		Transaction tx=null;
		try {
		     tx = session.beginTransaction();
		     session.saveOrUpdate(ur);
		     tx.commit();
		     return 0;
		}
		catch (Exception e) {
		     if (tx!=null) tx.rollback();
		     throw e;
		}
		finally {
		     session.close();
		}
	}
	public  List<UserRoles> getRoles() throws Exception{
		Session session =  ApplicationContext.getHiberSession().openSession();
		try {
		     String querystr="From UserRoles where id!=1";
		     Query query=session.createQuery(querystr);
		     List<UserRoles> queryresult=(List<UserRoles>)query.list();
		     return queryresult;
		}
		catch (Exception e) {
		     throw e;
		}
		finally {
		     session.close();
		}
	}

}
